home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / wiredsprites / common files / comframework.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  11.4 KB  |  334 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.h
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows. 
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <2>         01/14/00    rtm        added fGraphicsImporter field to window object record
  17. //       <1>         11/05/99    rtm        first file
  18. //
  19. //////////
  20.  
  21. #pragma once
  22.  
  23.  
  24. //////////
  25. //       
  26. // header files
  27. //       
  28. //////////
  29.  
  30. #ifndef __Prefix_File__
  31. #include <WinPrefix.h>
  32. #endif
  33.  
  34. #ifndef __CONTROLDEFINITIONS__
  35. #include <ControlDefinitions.h>
  36. #endif
  37.  
  38. #ifndef __FILETYPESANDCREATORS__
  39. #include <FileTypesAndCreators.h>
  40. #endif
  41.  
  42. #ifndef __MENUS__
  43. #include <Menus.h>
  44. #endif
  45.  
  46. #ifndef __MOVIES__
  47. #include <Movies.h>
  48. #endif
  49.  
  50. #ifndef __NAVIGATION__
  51. #include <Navigation.h>
  52. #endif
  53.  
  54. #ifndef __QUICKTIMEVR__
  55. #include <QuickTimeVR.h>
  56. #endif
  57.  
  58. #ifndef __RESOURCES__
  59. #include <Resources.h>
  60. #endif
  61.  
  62. #ifndef __SOUND__
  63. #include <Sound.h>
  64. #endif
  65.  
  66. #ifndef _STRING_H
  67. #include <string.h>
  68. #endif
  69.  
  70. #ifndef __TEXTUTILS__
  71. #include <TextUtils.h>
  72. #endif
  73.  
  74. #ifndef __QTUtilities__
  75. #include "QTUtilities.h"
  76. #endif
  77.  
  78. #include "ComResource.h"
  79.  
  80. #if TARGET_OS_WIN32
  81. #ifndef __QTML__
  82. #include <QTML.h>
  83. #endif
  84.  
  85. #include <shlobj.h>                                            // for SHAddToRecentDocs
  86. #endif
  87.  
  88. // revert to older names, to keep the linker happy
  89. #if TARGET_CPU_68K
  90. #define EnableMenuItem                        EnableItem
  91. #define DisableMenuItem                        DisableItem
  92. #endif
  93.  
  94.  
  95. //////////
  96. //
  97. // constants
  98. //
  99. //////////
  100.  
  101. #define kInvalidFileRefNum                    -1                // an invalid file reference number
  102.  
  103. #define kDefaultFileTypeCount                100                // a generous guess at the number of file types we can open
  104.  
  105. // constants for selecting InitApplication phase
  106. enum {
  107.     kInitAppPhase_BeforeCreateFrameWindow     = 1L << 0,        // MDI frame window is not yet created
  108.     kInitAppPhase_AfterCreateFrameWindow    = 1L << 1,        // MDI frame window is already created
  109.     kInitAppPhase_BothPhases                = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
  110. };
  111.  
  112. // constants for selecting StopApplication phase
  113. enum {
  114.     kStopAppPhase_BeforeDestroyWindows         = 1L << 0,        // movie windows are not yet torn down
  115.     kStopAppPhase_AfterDestroyWindows        = 1L << 1,        // movie windows are already torn down
  116.     kStopAppPhase_BothPhases                = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
  117. };
  118.  
  119. enum {
  120.     kApplicationSignature                      = FOUR_CHAR_CODE('QTsh')
  121. };
  122.  
  123. // parameters to the SetMenuItemState function
  124. #if TARGET_OS_MAC
  125. #define kEnableMenuItem                        0x00000000L
  126. #define kDisableMenuItem                    0x00000001L
  127. #endif
  128.  
  129. #if TARGET_OS_WIN32
  130. #define kEnableMenuItem                        MF_ENABLED
  131. #define kDisableMenuItem                    MF_GRAYED
  132. #endif
  133.  
  134. // constants for standard modal dialog filter proc
  135. #define kMyButtonDelay                        8
  136. #define kReturnKey                            (char)0x0D    
  137. #define kEnterKey                            (char)0x03    
  138. #define kEscapeKey                            (char)0x1B    
  139. #define kPeriod                                '.'
  140.  
  141. // items in Save Changes dialog box
  142. #if TARGET_OS_MAC
  143. #define kSaveChanges                        1                        // save the changes before closing window
  144. #define kCancelClose                        2                        // no, don't close the window or save changes
  145. #define kDontSaveChanges                    3                        // discard any unsaved changes
  146. #define kOKButtonUserItem                    4
  147. #endif
  148.  
  149. #if TARGET_OS_WIN32
  150. #define kSaveChanges                        IDYES                    // save the changes before closing window
  151. #define kCancelClose                        IDCANCEL                // no, don't close the window or save changes
  152. #define kDontSaveChanges                    IDNO                    // discard any unsaved changes
  153. #endif
  154.  
  155. // default name of a movie created by "New" menu command
  156. #if TARGET_OS_MAC
  157. #define kNewMovieName                        "untitled.mov"
  158. #endif
  159. #if TARGET_OS_WIN32
  160. #define kNewMovieName                        "C:\\untitled.mov"
  161. #endif
  162.  
  163. // default window positions
  164. #ifndef kDefaultWindowX
  165. #define kDefaultWindowX                        100
  166. #endif
  167.  
  168. #ifndef kDefaultWindowY
  169. #define kDefaultWindowY                        100
  170. #endif
  171.  
  172.  
  173. /////////
  174. //
  175. // macros
  176. //
  177. //////////
  178.  
  179. // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
  180. #define MENU_IDENTIFIER(menuID,menuItem)    ((menuID<<8)+(menuItem))
  181. #define MENU_ID(menuIdentifier)                ((menuIdentifier&0xff00)>>8)
  182. #define MENU_ITEM(menuIdentifier)            ((menuIdentifier&0x00ff))
  183.  
  184.  
  185. //////////
  186. //
  187. // data types
  188. //
  189. //////////
  190.  
  191. typedef const OSType *        QTFrameTypeListPtr;
  192.  
  193. #if TARGET_OS_MAC
  194. typedef MenuHandle            MenuReference;
  195. typedef WindowPtr            WindowReference;
  196. typedef NavObjectFilterUPP    QTFrameFileFilterUPP;
  197. #endif
  198.  
  199. #if TARGET_OS_WIN32
  200. typedef HMENU                MenuReference;
  201. typedef HWND                WindowReference;
  202. typedef FileFilterUPP        QTFrameFileFilterUPP;
  203. #endif
  204.  
  205.  
  206. //////////
  207. //
  208. // structures
  209. //
  210. //////////
  211.  
  212. // WindowObjectRecord is a data structure attached to a movie window.
  213. // We use this structure to associate data with any window presented.
  214. // If you have application-specific data that you want associated with
  215. // a movie or movie window, use the fAppData field to hold a handle to
  216. // that data.
  217.  
  218. typedef struct {
  219.     WindowReference            fWindow;            // the window
  220.     Movie                    fMovie;                // the movie
  221.     MovieController         fController;        // the movie controller
  222.     GraphicsImportComponent fGraphicsImporter;    // the graphics import component (if an image file)
  223.     FSSpec                    fFileFSSpec;        // location of the movie file
  224.     short                    fFileResID;            // the resource ID that the movie was loaded from
  225.     short                    fFileRefNum;        // the file reference number for the movie file
  226.     Boolean                    fCanResizeWindow;    // can the window be resized?
  227.     Boolean                    fIsDirty;            // has the movie data changed since the last save?
  228.     Boolean                    fIsQTVRMovie;        // is this a QuickTime VR movie?
  229.     QTVRInstance            fInstance;            // the QTVRInstance, if it's a QuickTime VR movie
  230.     OSType                    fObjectType;        // a tag indicating that the window object belongs to our application
  231.     Handle                    fAppData;            // a handle to application-specific window data
  232. } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
  233.  
  234.  
  235. //////////
  236. //
  237. // function prototypes
  238. //       
  239. //////////
  240.  
  241. // the following functions are defined in MacFramework.c and/or WinFramework.c
  242. void                        QTFrame_QuitFramework (void);
  243. WindowReference                QTFrame_CreateMovieWindow (void);
  244. void                         QTFrame_DestroyMovieWindow (WindowReference theWindow);
  245. void                         QTFrame_ShowAboutBox (void);
  246. void                        QTFrame_GetDisplayName (char *thePathName, char *theDispName);
  247.  
  248. // the following functions are defined in ComFramework.c
  249. void                        QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem);
  250. void                        QTFrame_HandleEditMenuItem (WindowReference theWindow, UInt16 theMenuItem);
  251. int                            QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu);
  252.  
  253. Boolean                     QTFrame_CreateNewMovie (void);
  254. Boolean                     QTFrame_OpenMovieInWindow (Movie theMovie, FSSpec *theFSSpec);
  255. MovieController                QTFrame_SetupController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
  256. OSErr                        QTFrame_SaveAsMovieFile (WindowReference theWindow);
  257. Boolean                     QTFrame_UpdateMovieFile (WindowReference theWindow);
  258. void                        QTFrame_IdleMovieWindows (void);
  259. void                        QTFrame_CloseMovieWindows (void);
  260. void                        QTFrame_CreateWindowObject (WindowReference theWindow);
  261. void                        QTFrame_CloseWindowObject (WindowObject theWindowObject);
  262.  
  263. WindowReference                QTFrame_GetFrontAppWindow (void);
  264. WindowReference                QTFrame_GetNextAppWindow (WindowReference theWindow);
  265. WindowReference                QTFrame_GetFrontMovieWindow (void);
  266. WindowReference                QTFrame_GetNextMovieWindow (WindowReference theWindow);
  267. WindowObject                QTFrame_GetWindowObjectFromFrontWindow (void);
  268. WindowObject                QTFrame_GetWindowObjectFromWindow (WindowReference theWnd);
  269. MovieController              QTFrame_GetMCFromFrontWindow (void);
  270. MovieController                QTFrame_GetMCFromWindow (WindowReference theWindow);
  271. QTVRInstance                QTFrame_GetQTVRInstanceFromFrontWindow (void);
  272. QTVRInstance                QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow);
  273. Handle                        QTFrame_GetAppDataFromFrontWindow (void);
  274. Handle                        QTFrame_GetAppDataFromWindow (WindowReference theWnd);
  275. Handle                        QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject);
  276. Boolean                     QTFrame_IsWindowObjectOurs (WindowObject theWindowObject);
  277. Boolean                        QTFrame_IsAppWindow (WindowReference theWindow);
  278. Boolean                        QTFrame_IsDocWindow (WindowReference theWindow);
  279. void                         QTFrame_ActivateController (WindowReference theWindow, Boolean IsActive);
  280.  
  281. void                        QTFrame_Beep (void);
  282. void                        QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuRank, short theState);
  283. void                        QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  284. void                        QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
  285. void                        QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
  286. GrafPtr                        QTFrame_GetPortFromWindowReference (WindowReference theWindow);
  287. WindowReference                QTFrame_GetWindowReferenceFromPort (GrafPtr thePort);
  288. WindowPtr                    QTFrame_GetWindowFromWindowReference (WindowReference theWindow);
  289. short                        QTFrame_GetWindowWidth (WindowReference theWindow);
  290. void                        QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs);
  291. void                        QTFrame_SizeWindowToMovie (WindowObject theWindowObject);
  292.  
  293. OSErr                        QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing);
  294. OSErr                        QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc);
  295. PASCAL_RTN void                QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD);
  296. Handle                        QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList);
  297. QTFrameFileFilterUPP        QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc);
  298. OSErr                        QTFrame_BuildFileTypeList (void);
  299. static void                    QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex);
  300.  
  301. #if TARGET_OS_MAC
  302. PASCAL_RTN Boolean            QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode);
  303. #endif
  304. #if TARGET_OS_WIN32
  305. PASCAL_RTN Boolean            QTFrame_FilterFiles (CInfoPBPtr thePBPtr);
  306. void                        QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect);
  307. void                        QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect);
  308. #endif
  309.  
  310.  
  311. //////////
  312. //
  313. // application-specific function prototypes
  314. //
  315. // These are defined in the file ComApplication.c; both MacFramework.c and WinFramework.c
  316. // call these functions at specific times; you can use them to customize a specific application.
  317. //       
  318. //////////
  319.  
  320. void                        QTApp_Init (UInt32 theStartPhase);
  321. void                        QTApp_Stop (UInt32 theStopPhase);
  322. void                        QTApp_Idle (WindowReference theWindow);
  323. void                        QTApp_Draw (WindowReference theWindow, Rect *theRefrehArea);
  324. void                         QTApp_HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
  325. Boolean                        QTApp_HandleKeyPress (char theCharCode);
  326. Boolean                     QTApp_HandleMenu (UInt16 theMenuItem);
  327. void                        QTApp_AdjustMenus (WindowReference theWindow, MenuReference theMenu);
  328. Boolean                        QTApp_HandleEvent (EventRecord *theEvent);
  329. void                        QTApp_SetupController (MovieController theMC);
  330. void                        QTApp_SetupWindowObject (WindowObject theWindowObject);
  331. void                        QTApp_RemoveWindowObject (WindowObject theWindowObject);
  332. PASCAL_RTN Boolean            QTApp_MCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);
  333.  
  334.